package com.LittleHan.crm.settings.service;

import com.LittleHan.crm.settings.dao.UserDao;
import com.LittleHan.crm.settings.entity.User;
import com.LittleHan.crm.exception.LoginException;
import com.LittleHan.crm.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;


@Service(value ="userServiceImpl")
public class UserServiceImpl implements  UserService{
    @Autowired
    @Qualifier(value="userDao")
    UserDao userDao;
    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public User login(String loginAct, String loginPwd, String allowIps) throws LoginException{
        User user=userDao.userLogin(loginAct,loginPwd);
        //
        System.out.println(user);
        //
        if(user==null){
            throw new LoginException("账号或密码错误1");
        }
        if(user.getExpireTime().compareTo(DateTimeUtil.getSysTime())<0){
            throw new LoginException("账号失效2");
        }
        if("0".equals(user.getLockState())){
            throw new LoginException("账号已锁定3");
        }
        if(!user.getAllowIps().contains(allowIps)){
            throw new LoginException("ip地址受限4");
        }
        return user;
    }
    public List<User> activityModelGetUserList(){
        List<User> list=userDao.activityGetUserList();
        return list;
    }
}
